<template>
  <div class="form-preview">
    <v-form-render  ref="vFormRef">
    </v-form-render>
    <div class="flex flex-center mt20 ">
      <el-button type="primary" @click="submitForm">确定</el-button>
    </div>
  </div>
</template>

<script lang='ts' setup>
import { ref, reactive, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import { useRoute } from 'vue-router';
const route = useRoute();
const vFormRef = ref()
declare var uni: any
const submitForm = () => {
  vFormRef.value.getFormData().then((formData: any) => {
    // Form Validation OK
    let dataJson = JSON.stringify(formData)
    uni.getEnv(function (res: any) {
      console.log(res);
      // if (res.h5) {
      uni.postMessage({
        data: {
          formData: dataJson
        }
      });
      // }

    });
  }).catch((error: any) => {
    // Form Validation failed
    ElMessage.error(error)
  })
}
const getRouteId = () => {
  let id = route.query.id
  if (id) {
    let paramsData = <any>route.query
    let formJson = paramsData?.formJson
    vFormRef.value.setFormJson(formJson)

  } else {
  }
} //获取路由ID
onMounted(() => {
  getRouteId()
})
</script>
<style scoped lang="scss">
.form-preview {
  height: 100%;
  width: 100%;
  position: relative;
  padding:10px 10px 10px 10px;
  overflow: auto;
}
</style>